package chapter13;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Caesar on 2016/2/25.
 */
public class Test10 {
    public static void main(String[] args) {
        matcher("^Java");
        matcher("\\Breg.*");
        matcher("n.w\\s+h(a|i)s");
        matcher("s?");
        matcher("s*");
        matcher("s+");
        matcher("s{4}");
        matcher("s{1}.");
        matcher("s{0,3}");

    }

    public static void matcher(String regex) {
        String s = "Java now has regular expressions";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(s);
        while (m.find())
            System.out.println("regx = " + regex + " : " + m.start() + "  " + m.end());
    }
}
